﻿using HLStock.MyType;
using System.Reflection;

namespace HLStock.DBAccess
{
    public class PropValueGetter
    {
        public PropValueGetter(PropertyInfo property)
        {
            PropName = property.Name;
            Property = property;
        }
        internal string PropName { get; private set; }
        PropertyInfo Property;
        internal object? Get(object record)
        {
            if (Property.PropertyType.IsEnum)
            {
                return (int)Property.GetValue(record)!;
            }
            if (typeof(IMyPropColumnType).IsAssignableFrom(Property.PropertyType))
            {
                IMyPropColumnType? i = Property.GetValue(record) as IMyPropColumnType;
                return i?.GetVal();
            }
            return Property.GetValue(record);
        }
    }
}
